<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:BetterWpfControls"
    xmlns:conv="clr-namespace:BetterWpfControls.Converters"
    xmlns:panels="clr-namespace:BetterWpfControls.Panels">

	<conv:IdentityConverter x:Key="CONV_Id" />
	<conv:NullToVisibilityConverter x:Key="CONV_NullToVisibility" />
	<conv:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />

	<SolidColorBrush x:Key="TabControlNormalBorderBrush" Color="#8C8E94"/>
	<SolidColorBrush x:Key="TabItemSelectedBackground" Color="#F9F9F9"/>
	<SolidColorBrush x:Key="TabItemHotBorderBrush" Color="#3C7FB1"/>
	<SolidColorBrush x:Key="TabItemDisabledBackground" Color="#F4F4F4"/>
	<SolidColorBrush x:Key="TabItemDisabledBorderBrush" Color="#FFC9C7BA"/>

	<LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
		<GradientStop Color="#F3F3F3" Offset="0"/>
		<GradientStop Color="#EBEBEB" Offset="0.5"/>
		<GradientStop Color="#DDDDDD" Offset="0.5"/>
		<GradientStop Color="#CDCDCD" Offset="1"/>
	</LinearGradientBrush>

	<LinearGradientBrush x:Key="TabItemHotBackground" EndPoint="0,1" StartPoint="0,0">
		<GradientStop Color="#EAF6FD" Offset="0.15"/>
		<GradientStop Color="#D9F0FC" Offset=".5"/>
		<GradientStop Color="#BEE6FD" Offset=".5"/>
		<GradientStop Color="#A7D9F5" Offset="1"/>
	</LinearGradientBrush>

	<Style TargetType="{x:Type local:MenuButton}">
		<Setter Property="SnapsToDevicePixels" Value="true"/>
		<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
		<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
		<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
		<Setter Property="VerticalAlignment" Value="Center" />
		<Setter Property="ContentBorderBrush" Value="LightGray" />
		<Setter Property="ContentBorderThickness" Value="0,0,0,1" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:MenuButton}">
					<Grid Background="{TemplateBinding Background}">
						<ToggleButton Name="ToggleButton" Opacity="1" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" HorizontalAlignment="Right" VerticalAlignment="{TemplateBinding VerticalAlignment}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
							<ToggleButton.Template>
								<ControlTemplate TargetType="ToggleButton">
									<Border Background="Transparent" Padding="{TemplateBinding Padding}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
										<StackPanel VerticalAlignment="Center">
											<Path x:Name="p1" Stroke="Gray" StrokeThickness="1" Fill="Gray" Data="M 0 0 H 10" Margin="0,3,0,0"/>
											<Path x:Name="p2" Stroke="Gray" StrokeThickness="1" Fill="Gray" Data="M 1 0 L 5 4 L 9 0 Z" Margin="0,3,0,0"/>
										</StackPanel>
									</Border>

									<ControlTemplate.Triggers>
										<Trigger Property="IsMouseOver" Value="True">
											<Setter TargetName="p1" Property="Stroke" Value="Gray" />
											<Setter TargetName="p2" Property="Fill" Value="Orange" />
										</Trigger>
									</ControlTemplate.Triggers>
								</ControlTemplate>
							</ToggleButton.Template>
						</ToggleButton>

						<Border BorderBrush="{TemplateBinding ContentBorderBrush}" BorderThickness="{TemplateBinding ContentBorderThickness}" Margin="0,0,16,0" Visibility="{Binding Content, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource CONV_NullToVisibility}}">
							<ContentPresenter ContentSource="Content" />
						</Border>

						<Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
							<Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
								<Border x:Name="DropDownBorder" Background="WhiteSmoke" BorderThickness="1" BorderBrush="Gray"/>
								<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
									<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
								</ScrollViewer>
							</Grid>
						</Popup>
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="HasItems" Value="false">
							<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
						</Trigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Foreground" Value="Gray"/>
						</Trigger>
						<Trigger Property="IsGrouping" Value="true">
							<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
						</Trigger>
						<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
							<Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/>
							<Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
						</Trigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="AlwaysShowToggleButton" Value="False" />
								<Condition Property="IsMouseOver" Value="False" />
							</MultiTrigger.Conditions>
							<Setter TargetName="ToggleButton" Property="Opacity" Value="0" />
						</MultiTrigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="{x:Type local:MenuButtonItem}">
		<Setter Property="Command" Value="{Binding Command, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MenuButton}}}" />
		<Setter Property="CommandParameter" Value="{Binding}" />
		<Setter Property="Background" Value="Transparent" />
		<Setter Property="BorderThickness" Value="1" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:MenuButtonItem}">
					<Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" Padding="3">
						<ContentPresenter />
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
		<Style.Triggers>
			<MultiTrigger>
				<MultiTrigger.Conditions>
					<Condition Property="IsMouseOver" Value="True" />
					<Condition Property="IsHighlightingEnabled" Value="True" />
				</MultiTrigger.Conditions>
				<Setter Property="BorderBrush" Value="LightBlue" />
				<Setter Property="Background" Value="Blue" />
				<Setter Property="Foreground" Value="White" />
			</MultiTrigger>
		</Style.Triggers>
	</Style>

	<Style TargetType="{x:Type local:ImageButton}">
		<Setter Property="Background" Value="Transparent" />
		<Setter Property="BorderThickness" Value="1" />
		<Setter Property="CornerRadius" Value="2" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:ImageButton}">
					<Border x:Name="bd" CornerRadius="{TemplateBinding CornerRadius}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
						<Image x:Name="img" Source="{TemplateBinding Source}" RenderOptions.BitmapScalingMode="HighQuality" />
					</Border>
					<ControlTemplate.Triggers>
						<Trigger Property="IsMouseOver" Value="True">
							<Setter TargetName="bd" Property="BorderBrush" Value="Gray" />
							<Setter TargetName="img"  Property="Effect">
								<Setter.Value>
									<DropShadowEffect BlurRadius="3" Color="#FF000000" Direction="-446" ShadowDepth="-2"/>
								</Setter.Value>
							</Setter>
						</Trigger>
						<Trigger Property="IsEnabled" Value="False">
							<Setter TargetName="img" Property="Opacity" Value="0.5" />
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="{x:Type local:SplitButton}">
		<Setter Property="HorizontalContentAlignment" Value="Center" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:SplitButton}">
					<Grid>
						<Button HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Command="{TemplateBinding Command}" CommandParameter="{TemplateBinding CommandParameter}">
							<ContentPresenter x:Name="cp" Margin="0,0,17,0" />
						</Button>
						<local:MenuButton x:Name="mb" IsDropDownOpen="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" Command="{TemplateBinding Command}" HorizontalAlignment="Right" VerticalAlignment="Stretch" Padding="4,0" BorderBrush="DarkGray" BorderThickness="1,0,0,0" ItemsSource="{Binding Items, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="ShowOptions" Value="False">
							<Setter TargetName="cp" Property="Margin" Value="0" />
							<Setter TargetName="mb" Property="Visibility" Value="Collapsed" />
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="{x:Type local:TabControl}">
		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
		<Setter Property="Padding" Value="4,4,4,4"/>
		<Setter Property="BorderThickness" Value="1"/>
		<Setter Property="BorderBrush" Value="{StaticResource TabControlNormalBorderBrush}"/>
		<Setter Property="Background" Value="#F9F9F9"/>
		<Setter Property="HorizontalContentAlignment" Value="Center"/>
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:TabControl}">
					<Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
						<Grid.ColumnDefinitions>
							<ColumnDefinition x:Name="ColumnDefinition0"/>
							<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
							<RowDefinition x:Name="RowDefinition1" Height="*"/>
						</Grid.RowDefinitions>

						<DockPanel>
							<local:MenuButton x:Name="PART_QuickLinksHost" Margin="1,2,0,0" DockPanel.Dock="Right" Panel.ZIndex="2" VerticalAlignment="Center" />
							<panels:ScrollablePanel IsItemsHost="True" x:Name="PART_HeaderPanel" Margin="2,2,2,0" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1" Grid.Column="0" Grid.Row="0" />
						</DockPanel>

						<Border x:Name="ContentPanel" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
							<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
						</Border>
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="TabStripPlacement" Value="Bottom">
							<Setter Property="Grid.Row" TargetName="PART_HeaderPanel" Value="1"/>
							<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
							<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
							<Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
							<Setter Property="Margin" TargetName="PART_HeaderPanel" Value="2,0,2,2"/>
						</Trigger>
						<Trigger Property="TabStripPlacement" Value="Left">
							<Setter Property="Grid.Row" TargetName="PART_HeaderPanel" Value="0"/>
							<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
							<Setter Property="Grid.Column" TargetName="PART_HeaderPanel" Value="0"/>
							<Setter Property="Grid.Column" TargetName="ContentPanel" Value="1"/>
							<Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
							<Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
							<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
							<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
							<Setter Property="Margin" TargetName="PART_HeaderPanel" Value="2,2,0,2"/>
						</Trigger>
						<Trigger Property="TabStripPlacement" Value="Right">
							<Setter Property="Grid.Row" TargetName="PART_HeaderPanel" Value="0"/>
							<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
							<Setter Property="Grid.Column" TargetName="PART_HeaderPanel" Value="1"/>
							<Setter Property="Grid.Column" TargetName="ContentPanel" Value="0"/>
							<Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
							<Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
							<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
							<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
							<Setter Property="Margin" TargetName="PART_HeaderPanel" Value="0,2,2,2"/>
						</Trigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="{x:Type local:TabItem}">
		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
		<Setter Property="Foreground" Value="Black"/>
		<Setter Property="Padding" Value="6,1,6,1"/>
		<Setter Property="BorderBrush" Value="{StaticResource TabControlNormalBorderBrush}"/>
		<Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
		<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
		<Setter Property="VerticalContentAlignment" Value="Stretch"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type local:TabItem}">
					<Grid SnapsToDevicePixels="true">
						<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1,1,1,0" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
							<ContentPresenter x:Name="Content" ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
						</Border>
					</Grid>
					<ControlTemplate.Triggers>
						<Trigger Property="IsMouseOver" Value="true">
							<Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemHotBackground}"/>
						</Trigger>
						<Trigger Property="IsSelected" Value="true">
							<Setter Property="Panel.ZIndex" Value="1"/>
							<Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemSelectedBackground}"/>
						</Trigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsSelected" Value="false"/>
								<Condition Property="IsMouseOver" Value="true"/>
							</MultiTrigger.Conditions>
							<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource TabItemHotBorderBrush}"/>
						</MultiTrigger>
						<Trigger Property="TabStripPlacement" Value="Bottom">
							<Setter Property="BorderThickness" TargetName="Bd" Value="1,0,1,1"/>
						</Trigger>
						<Trigger Property="TabStripPlacement" Value="Left">
							<Setter Property="BorderThickness" TargetName="Bd" Value="1,1,0,1"/>
						</Trigger>
						<Trigger Property="TabStripPlacement" Value="Right">
							<Setter Property="BorderThickness" TargetName="Bd" Value="0,1,1,1"/>
						</Trigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsSelected" Value="true"/>
								<Condition Property="TabStripPlacement" Value="Top"/>
							</MultiTrigger.Conditions>
							<Setter Property="Margin" Value="-2,-2,-2,-1"/>
							<Setter Property="Margin" TargetName="Content" Value="0,0,0,1"/>
						</MultiTrigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsSelected" Value="true"/>
								<Condition Property="TabStripPlacement" Value="Bottom"/>
							</MultiTrigger.Conditions>
							<Setter Property="Margin" Value="-2,-1,-2,-2"/>
							<Setter Property="Margin" TargetName="Content" Value="0,1,0,0"/>
						</MultiTrigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsSelected" Value="true"/>
								<Condition Property="TabStripPlacement" Value="Left"/>
							</MultiTrigger.Conditions>
							<Setter Property="Margin" Value="-2,-2,-1,-2"/>
							<Setter Property="Margin" TargetName="Content" Value="0,0,1,0"/>
						</MultiTrigger>
						<MultiTrigger>
							<MultiTrigger.Conditions>
								<Condition Property="IsSelected" Value="true"/>
								<Condition Property="TabStripPlacement" Value="Right"/>
							</MultiTrigger.Conditions>
							<Setter Property="Margin" Value="-1,-2,-2,-2"/>
							<Setter Property="Margin" TargetName="Content" Value="1,0,0,0"/>
						</MultiTrigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Background" TargetName="Bd" Value="{StaticResource TabItemDisabledBackground}"/>
							<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource TabItemDisabledBorderBrush}"/>
							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
</ResourceDictionary>